﻿using System;
using System.Collections.Generic;
using System.Text;
using Quanlynhasach.hethongluutru;
using Quanlynhasach.hethongxuly;
using System.Data;

namespace Quanlynhasach.hethongluutru
{
    class HoaDonDAO
    {
        public static DataTable LayDanhSachHoaDon()
        {
            string sql = "SELECT * FROM HoaDon";
            DataTable dt = database.ExcuQuery(sql);

            return dt;
          
        }
        public static DataTable LayDanhSachChiTietHoaDon()
        {
            string sql = "SELECT * FROM ChiTietHoaDon";
            DataTable dt = database.ExcuQuery(sql);

            return dt;

        }

        public static void ThemHoaDon(HoaDonDTO hdDTO)
        {
                string sql; 
                sql = "Insert into HoaDon(MaKhachHang, NgayLap) values  ("; 
                sql += hdDTO.maKhachHang.ToString() +","; 
                sql += "'" +hdDTO.NgayLap+ "')";
                database.ExcuNonQuery(sql);
         }
       
        public static void ThemChitietHoaDon(HoaDonDTO hdDTO)
        {
            string sql; 
           
            
            sql = "Insert into ChiTietHoaDon(MaHoaDon, MaSach,SoLuong, DonGiaBan) values ("; 
           
            sql += hdDTO.MaHoaDon.ToString() + ","; 
            sql += hdDTO.MaSach.ToString()+ ","; 
            sql += hdDTO.SoLuong.ToString() + ","; 
            sql += hdDTO.DonGiaBan.ToString() + ")";
            database.ExcuNonQuery(sql);
        }
    }

}
